package car;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.Calendar;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Font;
import commans.ErrorPage;

import main.CreatePolicyMain;
import main.MainFrame;
/*
 * CAPPM875
 * */
public class CarPolicyPrint extends CreatePolicyMain implements Runnable
{
    private static JProgressBar progressBar = new JProgressBar();
    private static JPanel contentPane;
    private static int currentValue;
    private static int count;
    private static File Obj;
    private static long totalBytes = 0;
    private static long byteRead = 0;

    public CarPolicyPrint()
    {
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setBounds(100,100,326,122);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5,5,5,5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        setLocationRelativeTo(null); // 視窗至中
        progressBar.setStringPainted(true);
        progressBar.setBounds(14,34,290,21);
        contentPane.add(progressBar);
        JLabel lblNewLabel = new JLabel("\u7522\u751F\u4E2D...........");
        lblNewLabel.setBounds(56,13,217,19);
        contentPane.add(lblNewLabel);
        setVisible(true);
        addWindowListener(new WindowAdapter()
        {
	  public void windowClosing(WindowEvent e)
	  {
	      System.exit(0);
	  }
        });

    }

    public void SetObj(File path)
    {
        Obj = path;
    }

    public void CreatePolicy(File obj)
    {
        try
        {
	  path = "C:\\temp.pdf";
	  Document document = new Document(PageSize.A4,10,-50,20,-50);// Document(設定格式,左,右,上,下)
	  System.out.println(getClass().getResource("/").getPath());
	  jpeg = Image.getInstance(getClass().getResource("/CarPolicy.jpg"));
	  jpeg.setAlignment(Image.UNDERLYING);
	  jpeg.scaleAbsolute(580,835);
	  jpeg.setAbsolutePosition(5,0);
	  PdfWriter.getInstance(document,new FileOutputStream(path));
	  // **********************設定字型*******************************************************************************************************
	  BaseFont bfChinese = BaseFont.createFont("C:\\windows\\fonts\\MINGLIU.TTC,1",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
	  Font FontChinese = new Font(bfChinese,8,Font.NORMAL);
	  Font FontChineseSmall = new Font(bfChinese,7,Font.NORMAL);

	  document.addTitle("MINGTAI");
	  document.addAuthor("MINGTAI");
	  document.addSubject("MINGTAI");
	  document.addKeywords("MINGTAI");
	  document.addCreator("MINGTAI");
	  document.open();

	  InputStreamReader isr = new InputStreamReader(new FileInputStream(obj.getPath()),"ISO8859_1");
	  BufferedReader br = new BufferedReader(isr);
	  while ( ( Line = br.readLine() )!=null)
	  {
	      count = count+1;
	  }
	  br.close();
	  isr.close();
	  // 設置初始值與最大值
	  progressBar.setValue(0);
	  progressBar.setMaximum(100);
	  totalBytes = count;

	  isr = new InputStreamReader(new FileInputStream(obj.getPath()),"ISO8859_1");
	  br = new BufferedReader(isr);
	  while ( ( Line = br.readLine() )!=null)
	  {
	      document.add(jpeg);// 載入圖檔
	      row[0] = Line.substring(0,8); // 保証號
	      row[1] = Line.substring(8,10); // 尾號
	      row[2] = Line.substring(10,19); // 保單號
	      row[3] = Line.substring(19,49); // 要保人
	      row[4] = Line.substring(49,59); // 要保人ＩＤ
	      row[5] = Line.substring(59,69); // 要保人電話
	      row[6] = Line.substring(69,72); // 要保人郵遞區號
	      row[7] = Line.substring(72,132); // 要保人地址
	      row[8] = Line.substring(132,162); // 被保險人
	      row[9] = Line.substring(162,172); // 電話
	      row[10] = Line.substring(172,232); // 地址
	      row[11] = Line.substring(232,235); // 郵遞區號
	      row[12] = Line.substring(235,265); // 受益人
	      row[13] = Line.substring(265,272); // 生效日 /年月日
	      row[14] = Line.substring(272,279); // 到期日 /年月日
	      row[15] = Line.substring(279,281); // 載客人數
	      row[16] = Line.substring(281,283); // 車種代號
	      row[17] = Line.substring(283,288); // 原始發照年月+1
	      row[18] = Line.substring(288,297); // 牌照號碼
	      row[19] = Line.substring(297,305); // 廠牌車型代號
	      row[20] = Line.substring(305,310); // 排氣量
	      row[21] = Line.substring(310,312); // 製造年份
	      row[22] = Line.substring(312,332); // 引擎號碼
	      row[23] = Line.substring(332,342); // 重置價格
	      row[24] = Line.substring(342,352); // 主駛人駕照號碼
	      row[25] = Line.substring(352,359); // 主駛人出生日 /年月日
	      row[26] = Line.substring(359,360); // 主駛人性別
	      row[27] = Line.substring(360,361); // 主駛人婚姻
	      row[28] = Line.substring(361,363); // 車體費率代號
	      row[29] = Line.substring(363,365); // 竊盜費率代號
	      row[30] = Line.substring(365,369); // 年齡性別係數
	      row[31] = Line.substring(369,371); // １-36險種
	      row[32] = Line.substring(371,387); // １-37險種
	      row[33] = Line.substring(387,393); // １-38保額
	      row[34] = Line.substring(393,394); // １-38保額
	      row[35] = Line.substring(394,404); // １-38保額
	      row[36] = Line.substring(404,409); // １-39自負額
	      row[37] = Line.substring(409,417); // １-40保費
	      row[38] = Line.substring(417,425); // １-40保費覆核
	      row[39] = Line.substring(425,435); // ２-42保額
	      row[40] = Line.substring(435,438); // ２-43自負額
	      row[41] = Line.substring(438,444); // ２-44保費
	      row[42] = Line.substring(444,450); // ２-45保費覆核
	      row[43] = Line.substring(450,451); // ３-46等等級
	      row[44] = Line.substring(451,452); // ３-46新等級
	      row[45] = Line.substring(452,462); // ３-46保額傷
	      row[46] = Line.substring(462,472); // ３-47保額總
	      row[47] = Line.substring(472,478); // ３-48保費
	      row[48] = Line.substring(478,484); // ３-49保費覆核
	      row[49] = Line.substring(484,494); // ４-50保額
	      row[50] = Line.substring(494,500); // ４-51保費
	      row[51] = Line.substring(500,506); // ４-52保費覆核
	      row[52] = Line.substring(506,512); // ５-53保費
	      row[53] = Line.substring(512,518); // ５-54保費覆核
	      row[54] = Line.substring(518,528); // ６-55保額傷
	      row[55] = Line.substring(528,538); // ６-56保額總
	      row[56] = Line.substring(538,548); // ６-59保額總
	      row[57] = Line.substring(548,554); // ６-57保費
	      row[58] = Line.substring(554,560); // ６-58保費覆核
	      row[59] = Line.substring(560,570); // ７-60保額傷
	      row[60] = Line.substring(570,580); // ７-61保額總
	      row[61] = Line.substring(580,584); // ７-64保額總
	      row[62] = Line.substring(584,587); // ７-64保額總
	      row[63] = Line.substring(587,593); // ７-62保費
	      row[64] = Line.substring(593,599); // ７-63保費覆核
	      row[65] = Line.substring(599,601); // 其他險種
	      row[66] = Line.substring(601,617); // 其他險種中文
	      row[67] = Line.substring(617,633); // 其他險種中文
	      row[68] = Line.substring(633,643); // 其他保額
	      row[69] = Line.substring(643,649); // 其他自負額
	      row[70] = Line.substring(649,657); // 其他保費 　
	      row[71] = Line.substring(657,665); // 其他庥費覆核
	      row[72] = Line.substring(665,667); // 其他險種
	      row[73] = Line.substring(667,683); // 其他險種中文
	      row[74] = Line.substring(683,699); // 其他險種中文
	      row[75] = Line.substring(699,709); // 其他保額
	      row[76] = Line.substring(709,715); // 其他自負額
	      row[77] = Line.substring(715,723); // 其他保費
	      row[78] = Line.substring(723,731); // 其他庥費覆核
	      row[79] = Line.substring(731,733); // 其他險種
	      row[80] = Line.substring(733,749); // 其他險種中文
	      row[81] = Line.substring(749,765); // 其他險種中文
	      row[82] = Line.substring(765,775); // 其他保額
	      row[83] = Line.substring(775,781); // 其他自負額
	      row[84] = Line.substring(781,789); // 其他保費
	      row[85] = Line.substring(789,797); // 其他庥費覆核
	      row[86] = Line.substring(797,799); // 其他險種
	      row[87] = Line.substring(799,815); // 其他險種中文
	      row[88] = Line.substring(815,831); // 其他險種中文
	      row[89] = Line.substring(831,841); // 其他保額
	      row[90] = Line.substring(841,847); // 其他自負額
	      row[91] = Line.substring(847,855); // 其他保費
	      row[92] = Line.substring(855,863); // 其他庥費覆核
	      row[93] = Line.substring(863,865); // 其他險種
	      row[94] = Line.substring(865,881); // 其他險種中文
	      row[95] = Line.substring(881,897); // 其他險種中文
	      row[96] = Line.substring(897,907); // 其他保額
	      row[97] = Line.substring(907,913); // 其他自負額
	      row[98] = Line.substring(913,921); // 其他保費
	      row[99] = Line.substring(921,929); // 其他庥費覆核
	      row[100] = Line.substring(929,931); // 其他險種
	      row[101] = Line.substring(931,947); // 其他險種中文
	      row[102] = Line.substring(947,963); // 其他險種中文
	      row[103] = Line.substring(963,973); // 其他保額
	      row[104] = Line.substring(973,979); // 其他自負額
	      row[105] = Line.substring(979,987); // 其他保費
	      row[106] = Line.substring(987,995); // 其他庥費覆核
	      row[107] = Line.substring(995,997); // 其他險種
	      row[108] = Line.substring(997,1013); // 其他險種中文
	      row[109] = Line.substring(1013,1029); // 其他險種中文
	      row[110] = Line.substring(1029,1039); // 其他保額
	      row[111] = Line.substring(1039,1045); // 其他自負額
	      row[112] = Line.substring(1045,1053); // 其他保費
	      row[113] = Line.substring(1053,1061); // 其他庥費覆核
	      row[114] = Line.substring(1061,1063); // 其他險種
	      row[115] = Line.substring(1063,1079); // 其他險種中文
	      row[116] = Line.substring(1079,1095); // 其他險種中文
	      row[117] = Line.substring(1095,1105); // 其他保額
	      row[118] = Line.substring(1105,1111); // 其他自負額
	      row[119] = Line.substring(1111,1119); // 其他保費
	      row[120] = Line.substring(1119,1127); // 其他庥費覆核
	      /*********************************************************************/
	      row[121] = Line.substring(1127,1137); // 任意險合計保費
	      row[122] = Line.substring(1137,1147); // 覆核任意保費
	      row[123] = Line.substring(1147,1157); // 強制証號
	      row[124] = Line.substring(1157,1159); // 強制新等級
	      row[125] = Line.substring(1159,1165); // 強制保費
	      row[126] = Line.substring(1165,1175); // 合計總保費
	      row[127] = Line.substring(1175,1182); // 強制生效日 年/月/日
	      row[128] = Line.substring(1182,1189); // 強制到期日 年/月/日
	      row[129] = Line.substring(1189,1203); // 關貿強制查詢序號
	      row[130] = Line.substring(1203,1213); // 銀行分行別
	      row[131] = Line.substring(1213,1224); // 銀行員工
	      row[132] = Line.substring(1224,1226); // 統計單位
	      row[133] = Line.substring(1226,1231); // 經手人
	      row[134] = Line.substring(1231,1236); // 服務人
	      row[135] = Line.substring(1236,1238); // 代理商代號
	      row[136] = Line.substring(1238,1240); // 通路記號 E
	      row[137] = Line.substring(1240,1247); // 收件單位及日期D
	      /**********************************************************************/
	      row[141] = Line.substring(1247,1249); // 車體加減費級數 C
	      row[142] = Line.substring(1249,1251); // 責任新等級 B
	      row[140] = Line.substring(1251,1271); // 關貿任意查詢序號
	      row[138] = Line.substring(1271,1275); // 賠款次數車體
	      row[139] = Line.substring(1275,1279); // 賠款次數責任

	      // 中文轉碼
	      row[3] = new String(row[3].getBytes("ISO8859_1"),"MS950");
	      row[7] = new String(row[7].getBytes("ISO8859_1"),"MS950");
	      row[8] = new String(row[8].getBytes("ISO8859_1"),"MS950");
	      row[10] = new String(row[10].getBytes("ISO8859_1"),"MS950");
	      row[12] = new String(row[12].getBytes("ISO8859_1"),"MS950");
	      row[9] = new String(row[9].getBytes("ISO8859_1"),"MS950");
	      row[32] = new String(row[32].getBytes("ISO8859_1"),"MS950");
	      row[66] = new String(row[66].getBytes("ISO8859_1"),"MS950");
	      row[67] = new String(row[67].getBytes("ISO8859_1"),"MS950");
	      row[73] = new String(row[73].getBytes("ISO8859_1"),"MS950");
	      row[74] = new String(row[74].getBytes("ISO8859_1"),"MS950");
	      row[80] = new String(row[80].getBytes("ISO8859_1"),"MS950");
	      row[81] = new String(row[81].getBytes("ISO8859_1"),"MS950");
	      row[87] = new String(row[87].getBytes("ISO8859_1"),"MS950");
	      row[88] = new String(row[88].getBytes("ISO8859_1"),"MS950");
	      row[94] = new String(row[94].getBytes("ISO8859_1"),"MS950");
	      row[95] = new String(row[95].getBytes("ISO8859_1"),"MS950");
	      row[101] = new String(row[101].getBytes("ISO8859_1"),"MS950");
	      row[102] = new String(row[102].getBytes("ISO8859_1"),"MS950");
	      row[108] = new String(row[108].getBytes("ISO8859_1"),"MS950");
	      row[109] = new String(row[109].getBytes("ISO8859_1"),"MS950");
	      row[115] = new String(row[115].getBytes("ISO8859_1"),"MS950");
	      row[116] = new String(row[116].getBytes("ISO8859_1"),"MS950");

	      // 寫入PDF
	      // ***************************汽車保險要保書************************************************************************

	      document.add(new Paragraph("分行代號： "+row[130]+"\n行員代號："+row[131],FontChinese));
	      document.add(new Paragraph(" ",FontChinese));
	      document.add(new Paragraph(" ",FontChinese));
	      document.add(new Paragraph(" ",FontChinese));
	      // 保險卡號寶單號

	      document.add(new Paragraph(14,"                                                                                                                                                                                                                             "+row[123],FontChinese));
	      document.add(new Paragraph(18,"                                                                                                                                                                                                                             "+row[2],FontChinese));
	      // ******被保人*****************
	      str1 = MakesUpSpace(row[8],row[8].length());
	      str2 = MakesUpSpace2(row[9],row[9].length());
	      str4 = MakesUpSpace2(row[10],row[10].length());
	      // 被保險人姓名
	      document.add(new Paragraph(22,"                              "+str1,FontChinese));
	      // 被保人出生年
	      document.add(new Paragraph(0,"                                                                                                                                                   "+CatZero(row[25].substring(0,3)),FontChinese));
	      // 被保人出生月
	      document.add(new Paragraph(0,"                                                                                                                                                             "+row[25].substring(3,5),FontChinese));
	      // 被保人出生日
	      document.add(new Paragraph(0,"                                                                                                                                                                       "+row[25].substring(5,7),FontChinese));
	      // 被保人性別
	      document.add(new Paragraph(0,"                                                                                                                                                                                                 "+row[26],FontChinese));
	      // 被保人婚姻
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                                                "+row[27],FontChinese));
	      // 被保險人ID
	      document.add(new Paragraph(15,"                              "+row[24],FontChinese));
	      // 被保人通訊地址
	      document.add(new Paragraph(13,"                              "+row[11],FontChinese));
	      document.add(new Paragraph(0,"                                         "+str4,FontChineseSmall));
	      // 被保人電話
	      document.add(new Paragraph(0,"                                                                                                                                                              "+str2,FontChinese));
	      // ******要保人******************
	      row[7] = MakesUpSpace2(row[7],row[7].length());
	      row[3] = MakesUpSpace(row[3],row[3].length());
	      // 要保人姓名
	      document.add(new Paragraph(14,"                                                      "+row[3],FontChinese));
	      // 要保人ID
	      document.add(new Paragraph(12,"                              "+row[4],FontChinese));
	      // 要保人通訊地址
	      document.add(new Paragraph(14,"                              "+row[6],FontChinese));
	      document.add(new Paragraph(0,"                                         "+row[7],FontChineseSmall));
	      // 要保人電話
	      document.add(new Paragraph(0,"                                                                                                                                                              "+row[5],FontChinese));

	      // 受益人
	      row[12] = MakesUpSpace2(row[12],row[12].length());
	      document.add(new Paragraph(14,"                               "+row[12],FontChinese));
	      // 保險期間
	      if(row[13].equals("0000000")||row[14].equals("0000000"))
	      {
		row[13] = "       ";
		row[14] = "       ";
	      }
	      document.add(new Paragraph(13,"                                      "+row[13].substring(0,3)+"             "+row[13].substring(3,5)+"        "+row[13].substring(5,7),FontChinese));
	      // 乘載限制
	      String people = "";
	      if(row[15].equals("00"))
	      {
		row[15] = "";
	      }
	      else
	      {
		row[15] = CatZero(row[15]);
		people = row[15]+"人";
	      }
	      document.add(new Paragraph("                                      "+row[14].substring(0,3)+"             "+row[14].substring(3,5)+"        "+row[14].substring(5,7)+"                                                                                                                                                                                                 "+people,FontChinese));
	      // 車種代號　原始發照　牌照號碼　車輛代號　排氣量　製造年份
	      String remoney;
	      remoney = CatZero(row[23]);
	      document.add(new Paragraph(29,"     "+row[16],FontChinese));
	      document.add(new Paragraph(0,"                                "+CatZero(row[17].substring(0,3))+"          "+row[17].substring(3,5),FontChinese));
	      // 牌照號碼
	      document.add(new Paragraph(0,"                                                                 "+row[18],FontChinese));
	      // 車輛廠牌形式代號
	      document.add(new Paragraph(0,"                                                                                                  "+row[19],FontChinese));
	      // 排氣量
	      document.add(new Paragraph(0,"                                                                                                                                       "+CatZero(row[20]),FontChinese));
	      // 製造年分
	      int createyear = Integer.parseInt(row[21]);
	      if(createyear>=74)
	      {
		createyear = createyear+1900;
	      }
	      else
	      {
		createyear = createyear+2000;
	      }
	      document.add(new Paragraph(0,"                                                                                                                                                                               "+createyear,FontChinese));
	      // 引擎號碼
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                 "+row[22],FontChinese));
	      // 重置價格
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                                                            "+remoney,FontChinese));

	      if(row[25].equals("0000000"))// 無日期帶空白
	      {
		row[25] = "       ";
	      }
	      if(row[26].equals("0"))
	      {
		row[26] = " ";
	      }
	      if(row[27].equals("0"))
	      {
		row[27] = " ";
	      }

	      // 車體費率代號
	      document.add(new Paragraph(48,"                                  "+row[28],FontChinese));
	      // 竊盜費率代號
	      document.add(new Paragraph(0,"                                                                                                 "+row[29],FontChinese));
	      // 年齡性別係數
	      document.add(new Paragraph(0,"                                                                                                                                                                  "+row[30],FontChinese));

	      // 31~64險種 種類 保險金額 自負額 保險費 核覆
	      // 車體損失險
	      String money35 = ( CatZero(row[35]) );
	      String money36 = ( CatZero(row[36]) );
	      String money37 = ( CatZero(row[37]) );
	      String money38 = ( CatZero(row[38]) );
	      document.add(new Paragraph(53,"  "+row[31],FontChinese));
	      document.add(new Paragraph(0,"            "+row[32],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                 "+money35,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                  "+money36,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money37,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money38,FontChinese));

	      // 竊盜損失險
	      row[39] = ( CatZero(row[39]) );
	      String money40 = ( CatZero(row[40]) );
	      String money41 = ( CatZero(row[41]) );
	      String money42 = ( CatZero(row[42]) );
	      document.add(new Paragraph(18,"                                                                                                                 "+row[39],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                  "+money40,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money41,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money42,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                                              "+row[137],FontChinese));
	      // 汽車第三責任險
	      String money45 = ( CatZero(row[45]) );
	      String money46 = ( CatZero(row[46]) );
	      String money47 = ( CatZero(row[47]) );
	      String money48 = ( CatZero(row[48]) );
	      String money49 = ( CatZero(row[49]) );
	      String money50 = ( CatZero(row[50]) );
	      String money51 = ( CatZero(row[51]) );
	      document.add(new Paragraph("                                                                                                                 "+money45,FontChinese));
	      document.add(new Paragraph("                                                                                                                 "+money46,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money47,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money48,FontChinese));
	      document.add(new Paragraph(14,"                                                                                                                 "+money49,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money50,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money51,FontChinese));
	      // 受酒精附加條款
	      String money52 = ( CatZero(row[52]) );
	      String money53 = ( CatZero(row[53]) );
	      document.add(new Paragraph("     ",FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money52,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money53,FontChinese));
	      // 汽車第三責任險乘客體商責任附加條款
	      String money54 = ( CatZero(row[54]) );
	      // String money55 = (CatZero(row[55]));
	      String money56 = ( CatZero(row[56]) );
	      String money57 = ( CatZero(row[57]) );
	      String money58 = ( CatZero(row[58]) );
	      document.add(new Paragraph(14,"                                                                                                                 "+money54,FontChinese));
	      document.add(new Paragraph("  ",FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money57,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money58,FontChinese));
	      document.add(new Paragraph(3,"                                                                                                                 "+money56,FontChinese));
	      // //汽車第三責任險乘附加駕駛人傷害保險
	      String money59 = ( CatZero(row[59]) );
	      String money60 = ( CatZero(row[60]) );
	      String money61 = ( CatZero(row[61]) );
	      String day2 = ( CatZero(row[62]) );
	      String money63 = ( CatZero(row[63]) );
	      String money64 = ( CatZero(row[64]) );
	      document.add(new Paragraph(12,"                                                                                                                 "+money59,FontChinese));
	      document.add(new Paragraph("                                                                                                                 "+money60,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+money63,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+money64,FontChinese));
	      document.add(new Paragraph("                                                                                                              "+money61+"                     "+day2,FontChinese));
	      // 其他險種1
	      row[68] = CatZero(row[68]);
	      row[69] = CatZero(row[69]);
	      row[70] = CatZero(row[70]);
	      row[71] = CatZero(row[71]);
	      document.add(new Paragraph(CutPolicyNumber(row[65])+"   "+row[66]+" "+row[67]+"                                             "+row[68]+"                       "+row[69],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[70],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[71],FontChinese));
	      // 其他險種2
	      row[75] = CatZero(row[75]);
	      row[76] = CatZero(row[76]);
	      row[77] = CatZero(row[77]);
	      row[78] = CatZero(row[78]);
	      document.add(new Paragraph(CutPolicyNumber(row[72])+"   "+row[73]+" "+row[74]+"                                             "+row[75]+"                       "+row[76],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[77],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[78],FontChinese));
	      // 其他險種3
	      row[82] = CatZero(row[82]);
	      row[83] = CatZero(row[83]);
	      row[84] = CatZero(row[84]);
	      row[85] = CatZero(row[85]);
	      document.add(new Paragraph(CutPolicyNumber(row[79])+"   "+row[80]+" "+row[81]+"                                             "+row[82]+"                       "+row[83],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[84],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[85],FontChinese));
	      // 其他險種4
	      row[89] = CatZero(row[89]);
	      row[90] = CatZero(row[90]);
	      row[91] = CatZero(row[91]);
	      row[92] = CatZero(row[92]);
	      document.add(new Paragraph(CutPolicyNumber(row[86])+"   "+row[87]+" "+row[88]+"                                             "+row[89]+"                       "+row[90],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[91],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[92],FontChinese));
	      // 其他險種5
	      row[96] = CatZero(row[96]);
	      row[97] = CatZero(row[97]);
	      row[98] = CatZero(row[98]);
	      row[99] = CatZero(row[99]);
	      document.add(new Paragraph(CutPolicyNumber(row[93])+"   "+row[94]+" "+row[95]+"                                             "+row[96]+"                       "+row[97],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[98],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[99],FontChinese));
	      // 其他險種6
	      row[103] = CatZero(row[103]);
	      row[104] = CatZero(row[104]);
	      row[105] = CatZero(row[105]);
	      row[106] = CatZero(row[106]);
	      document.add(new Paragraph(CutPolicyNumber(row[100])+"  "+row[101]+" "+row[102]+"                                           "+row[103]+"                       "+row[104],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[105],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[106],FontChinese));
	      // 其他險種7
	      row[110] = CatZero(row[110]);
	      row[111] = CatZero(row[111]);
	      row[112] = CatZero(row[112]);
	      row[113] = CatZero(row[113]);
	      document.add(new Paragraph(CutPolicyNumber(row[107])+"  "+row[108]+" "+row[109]+"                                           "+row[110]+"                       "+row[111],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[112],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[113],FontChinese));
	      // 其他顯種8
	      row[117] = CatZero(row[117]);
	      row[118] = CatZero(row[118]);
	      row[119] = CatZero(row[119]);
	      row[120] = CatZero(row[120]);
	      document.add(new Paragraph(CutPolicyNumber(row[114])+"  "+row[115]+" "+row[116]+"                                           "+row[117]+"                       "+row[118],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+row[119],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                     "+row[120],FontChinese));
	      String anypmoney = CatZero(row[121]);
	      String repmoney = CatZero(row[120]);
	      String forcemoney = CatZero(row[125]);
	      String totalemoney = CatZero(row[126]);
	      // 任意保險費
	      document.add(new Paragraph(1,"                                                                                                                                                                                          "+anypmoney,FontChinese));
	      // 覆核總費用
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                  "+repmoney,FontChinese));
	      // 係數等級
	      if(row[124].equals("00"))
	      {
		row[124] = "  ";
	      }
	      document.add(new Paragraph(15,"                                                                                                      "+row[124],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                           "+forcemoney,FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                                                                              "+totalemoney,FontChinese));
	      // 強制保險證號碼
	      if(row[127].equals("0000000")||row[128].equalsIgnoreCase("0000000"))// 無日期帶空白
	      {
		row[127] = "       ";
		row[128] = "       ";
	      }
	      document.add(new Paragraph(17,"                                              "+row[127].substring(0,3)+"       "+row[127].substring(3,5)+"       "+row[127].substring(5,7)+"                                        "+row[128].substring(0,3)+"       "+row[128].substring(3,5)+"       "+row[128].substring(5,7)+"                                                                                                 "+row[129],FontChinese));
	      document.add(new Paragraph(126,row[136]+"               "+row[132],FontChinese));
	      document.add(new Paragraph(38,"                                                                                                                                                                 "+row[140],FontChineseSmall));
	      // 賠款紀錄係數
	      document.add(new Paragraph(26,"                                                                                                                                                                             "+row[142],FontChinese));
	      document.add(new Paragraph(0,"                                                                                                                                                                                              "+row[141],FontChinese));
	      // document.add(new
	      // Paragraph(12,"                                                                                                                                                                 "+row[139],FontChinese));
	      // document.add(new
	      // Paragraph(0,"                                                                                                                                                                                 "+row[138],FontChinese));
	      document.newPage();
	      // ************ProgressBar****************************
	      byteRead = byteRead+1;
	      currentValue = (int) ( byteRead*100/totalBytes );
	      progressBar.setValue(currentValue);
	  }
	  document.close();
	  path = function.ChangeBankName("",path,"汽車要保書","彩色列印");
	  JOptionPane.showMessageDialog(null,path);
	  br.close();
	  dispose();
	  // 執行完畢後開啟PDF檔/
	  // Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "
	  // + path);
        }
        catch (Exception e1)
        {
	  document.close();
	  new ErrorPage(e1);
        }
    }

    @Override
    public void run()
    {
        CreatePolicy(Obj);
    }

}
